package net.pulseproject.commons.midi.entity;

public enum DeviceState {

	TRANSMITTING_ONLY(true, false),
	RECEIVING_ONLY(false, true),
	BIDIRECTIONAL(true, true),
	NONE(false, false);
	
	private final boolean transmitting;
	
	private final boolean receiving;
	
	private DeviceState(final boolean transmitting, final boolean receiving) {
		this.transmitting = transmitting;
		this.receiving = receiving;
	}

	public static DeviceState byMaxReceiversTransmitters(final int maxReceivers, final int maxTransmitters) {
		if(maxTransmitters == 0 && maxReceivers == 0) {
			return DeviceState.NONE;
		}
		
		if(maxTransmitters != 0 && maxReceivers == 0) {
			return DeviceState.TRANSMITTING_ONLY;
		}
		
		if(maxTransmitters == 0 && maxReceivers != 0) {
			return DeviceState.RECEIVING_ONLY;
		}
		
		assert (maxTransmitters != 0 && maxReceivers != 0);
		return DeviceState.BIDIRECTIONAL;
	}
	
	public boolean isTransmitting() {
		return this.transmitting;
	}
	
	public boolean isReceiving() {
		return this.receiving;
	}
}
